package com.example.springboot.subscribe;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Fanout Exchange（订阅模式）
 * Fanout 就是我们熟悉的广播模式或者订阅模式，给Fanout交换机发送消息，绑定了这个交换机的所有队列都收到这个消息
 * @program: 12-springboot-rabbitmq
 * @description: SubscribeRabbitConfig
 * @author: Yuwl
 * @create: 2019-12-27 17:45
 **/
@Configuration
public class SubscribeRabbitConfig {

	@Bean
	public Queue aQueue() {
		return new Queue("q_fanout_A");
	}

	@Bean
	public Queue bQueue() {
		return new Queue("q_fanout_B");
	}

	@Bean
	public Queue cQueue() {
		return new Queue("q_fanout_C");
	}

	@Bean
	public FanoutExchange fanoutExchange() {
		return new FanoutExchange("mybootfanoutExchange");
	}

	@Bean
	public Binding bindingExchangeA(Queue aQueue, FanoutExchange fanoutExchange) {
		return BindingBuilder.bind(aQueue).to(fanoutExchange);
	}

	@Bean
	public Binding bindingExchangeB(Queue bQueue, FanoutExchange fanoutExchange) {
		return BindingBuilder.bind(bQueue).to(fanoutExchange);
	}

	@Bean
	public Binding bindingExchangeC(Queue cQueue, FanoutExchange fanoutExchange) {
		return BindingBuilder.bind(cQueue).to(fanoutExchange);
	}
}
